﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SalaryChannel.SCPublicInforService;

namespace SalaryChannel
{
    public partial class PublicInforAddControl : UserControl
    {
        public PublicInforAddControl()
        {
            InitializeComponent();
            ExpireDate.DisplayDateStart = DateTime.Now.AddDays(1);
            ExpireDate.DisplayDate = DateTime.Now.AddMonths(1);
            
            ServiceInstance.PublicInforClient.AddPublicInofrCompleted += new EventHandler<AddPublicInofrCompletedEventArgs>(dclient_AddPublicInofrCompleted);
            
        }

      

      
        private void CommitBtn_Click(object sender, RoutedEventArgs e)
        {
            string body = BodyTB.Text.Trim();
            if (string.IsNullOrEmpty(body))
            {
                App.MessageBox.ShowDialog(Properties.Resource.BulltinWarning, Title.Warning);
                return;

            }
            ServiceInstance.PublicInforClient.AddPublicInofrAsync(body, this.ExpireDate.Text, App.CurrentUser.UserID.ToString());
        }

        void dclient_AddPublicInofrCompleted(object sender, AddPublicInofrCompletedEventArgs e)
        {
            string msg = string.Empty;
            try
            {
                if (e.Result)
                {
                    msg = Properties.Resource.Succeeded;
                    this.BodyTB.Text = string.Empty;
                }
                else
                {
                    msg = Properties.Resource.TryAgain;
                }
            }
            catch 
            {
                msg = Properties.Resource.TryAgain;
            }
            finally
            {
                App.MessageBox.ShowDialog(msg, Title.Information);
            }

        }
    }
}
